package com.qf.fmall2302.config;

import com.qf.fmall2302.filter.JwtFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注意，为了不让 自定义filter也被中注册到全局FitlterChain中，
 * 需要添加如下配置类
 */
@Configuration
public class FilterConfig {

    @Autowired
    JwtFilter jwtFilter;

    @Bean
    public FilterRegistrationBean<JwtFilter> jwtFilterFilterRegistrationBean(){
        FilterRegistrationBean<JwtFilter> registrationBean = new FilterRegistrationBean<>();

        //要注册的filter的对象
        registrationBean.setFilter(jwtFilter);

        // 让当前filter不要注册到 全局过滤器链上
        registrationBean.setEnabled(false);

        //处理filter的url路径
        registrationBean.addUrlPatterns("/index/indeximg");
        return registrationBean;

    }


}
